/*
  根据用户的请求, 响应不同的内容
        /index.html       this is index.html
        /login.html       this is login.html
        /register.html    this is register.html
        其他地址           this is 404
*/

// const http = require('http')

// const server = http.createServer()

// server.listen(3000, ()=> {
//   console.log('启动成功~');
// })

// server.on('request', (req, res) => {
//   console.log(req.url);
//   if (req.url === '/index.html') {
//     res.end('this is index.html')
//   } else if (req.url === '/login.html') {
//     res.end('this is login.html')
//   } else if (req.url === '/register.html') {
//     res.end('this is register.html')
//   } else {
//     // 设置状态码 不存在的资源
//     res.statusCode = 404  
//     res.statusMessage = '404 is 404'  // 状态信息
//     res.end('this is 404')
//   }
// })

// const http = require('http')
// const server = http.createServer()
// server.listen(3004,()=>{
//   console.log('服务器启动成功');
// })
// server.on('request',(req,res)=>{
//   console.log(req.url);
//   if(req.url === '/index.html'){
//     res.end('this is index.html')
//   }else if(req.url === '/register.html'){
//     res.end('this is register.html')
//   }else if(req.url === '/login.html'){
//     res.end('this is login.html')
//   }else{
//     res.statusCode = 404
//     res.statusMessage = '404 is 404'
//     res.end('this is 404')
//   }
  

// })

const http = require('http')
const server = http.createServer()
server.listen(3006,()=>{
  console.log('服务启动了');
})
server.on('request',(req,res)=>{
  if(req.url==='/index.html'){
    res.end('this is index.html')
  }else if(req.url==='/login.html'){
    res.end('this is login.html')
  }else if(req.url === '/register.html'){
    res.end('this is register.html')
  }else{
    res.end('this is 404')
  }
})
